home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 February / PC Plus Super CD (Issue 124) (PCP124-2-97) (February 1997).iso / handson / delphi / outline1 / outline1.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-10-14  |  1.8 KB  |  75 lines

  1. unit Outline1;
  2. { PC PLUS example program.
  3.  
  4.   A simple example of how to use the Delphi Outline component.
  5.  
  6.   This is an implementation of a sample project described in the
  7.   Delphi Help System. We have merely added a few checks and error
  8.   messages to the SpeedButton1Click method.
  9. }
  10. interface
  11.  
  12. uses
  13.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  14.   Forms, Dialogs, StdCtrls, Buttons, Grids, Outline;
  15.  
  16. type
  17.   TForm1 = class(TForm)
  18.     Outline1: TOutline;
  19.     Edit1: TEdit;
  20.     Edit2: TEdit;
  21.     SpeedButton1: TSpeedButton;
  22.     Label1: TLabel;
  23.     Label2: TLabel;
  24.     Label3: TLabel;
  25.     Label4: TLabel;
  26.     procedure SpeedButton1Click(Sender: TObject);
  27.     procedure Outline1Expand(Sender: TObject; Index: Longint);
  28.     procedure Outline1Click(Sender: TObject);
  29.   private
  30.     { Private declarations }
  31.   public
  32.     { Public declarations }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.  
  38. implementation
  39.  
  40. {$R *.DFM}
  41.  
  42. procedure TForm1.SpeedButton1Click(Sender: TObject);
  43. var
  44.   AddStr: string;
  45.   AddIndex :LongInt;
  46.   Code : Integer;
  47. begin
  48.  AddStr := Edit1.Text;
  49.  Val(Edit2.Text, AddIndex, Code);
  50.   { Error during conversion to integer? }
  51.   if Code <> 0 then
  52.     MessageDlg('Invalid index number.', mtWarning, [mbOk], 0)
  53.   else
  54.   if AddIndex > Outline1.Lines.Count then
  55.     MessageDlg('Index exceeds number of items in outline!',mtWarning, [mbOk], 0)
  56.   else
  57.   if Edit1.Text = '' then
  58.     MessageDlg('Please enter text for this item.', mtWarning, [mbOk], 0)
  59.   else
  60.     Outline1.AddChild(AddIndex, AddStr);
  61.  Label2.Caption := IntToStr(Outline1.SelectedItem);
  62. end;
  63.  
  64. procedure TForm1.Outline1Expand(Sender: TObject; Index: Longint);
  65. begin
  66.   Label2.Caption := IntToStr(Outline1.SelectedItem);
  67. end;
  68.  
  69. procedure TForm1.Outline1Click(Sender: TObject);
  70. begin
  71.   Label2.Caption := IntToStr(Outline1.SelectedItem);
  72. end;
  73.  
  74. end.
  75.